home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 684 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  2. Message-ID: <4i09ap$35n@mulga.cs.mu.OZ.AU>
  3. X-Original-Date: 11 Mar 1996 04:14:17 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 11 Mar 96 04:18:48 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: extern inlines
  9. Organization: Comp Sci, University of Melbourne
  10. References: <smeyersDo1L8o.99t@netcom.com>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMUOpyeEDnX0m9pzZAQG/3QF/ezVneGt6fPGNgZUIkkvWG+9TJQXxcviJ
  13.     FBVo0AeLrGS3WkTX1LFv4vvPJ33KXQyl
  14.     =Fg6x
  15.  
  16. smeyers@netcom.com (Scott Meyers) writes:
  17.  
  18. >I'm a little confused about the meaning of extern inline functions.
  19. >DWP 7.1.1.4 makes it clear that extern inline functions have external
  20. >linkage, so I have two questions.
  21. >
  22. >1.  Suppose this definition occurs in header1.h:
  23. >
  24. >      extern inline f() { cout << "Hello."; }
  25. >    
  26. >    Further suppose that header1.h is #included by file1.cpp, file2.cpp, and
  27. >    file3.cpp and that, for whatever reason, f is NOT inlined.  Which object
  28. >    file will contain the definition of f?  My understanding is that only
  29. >    one of them will.
  30.  
  31. The C++ standard does not define the notion of an "object file".
  32. Not all implementations use object files.  (For example, C++ interpreters
  33. may just load the source files into memory.)
  34.  
  35. However, I think typical implementations will place a definition of f()
  36. in every object file, and then merge them at link time to ensure that
  37. the final executable only contains one definition of f().
  38.  
  39. If you want to find out what your particular implementation does, try
  40. compiling to assembler (often the `-S' compiler option will have this
  41. effect) and examining the assembler file, or try exaxmining the object
  42. file (on Unix implementations, you can use the `nm' command to do
  43. this).
  44.  
  45. >2.  Now suppose there is a second header file header2.h, which contains
  46. >    this definition:
  47. >
  48. >      extern inline f() { cout << "Goodbye."; }  // note that this is
  49. >                                                 // not the same as f above
  50. >
  51. >    If I link together an object file containing the definition of f
  52. >    from header1.h and another object file containing the definition of
  53. >    f from header2.h, am I correct in assuming that the resulting
  54. >    program violates the one definition rule and that this violation
  55. >    need not be diagnosed?
  56.  
  57. Yes.
  58.  
  59. --
  60. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  61. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  62. ---
  63. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  64. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  65. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  66. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  67. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  68.